
package csc.daonjpa.java.controller;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import csc.daonjpa.java.dao.AccountDAO;
import csc.daonjpa.java.dao.CardDAO;
import csc.daonjpa.java.dao.CustomerDAO;
import csc.daonjpa.java.domain.Card;
import csc.daonjpa.java.domain.Customer;

/**
 * This controller handles account related actions
 * @author nvu3
 *
 */
@Controller
public class Execise2Controller {
	/**
	 * Adds account to DB
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/execise2")
	public String addAccount(HttpServletRequest request, Model model) {
		long counter  = 20;
		long customerId  = 20;
		long baseInfoId  = 20;
		CustomerDAO customerDAO = new CustomerDAO();
		CardDAO cardDAO = new CardDAO();
		
		Customer customer1 = new Customer();
		customer1.setLoginId(customerId++);
		customer1.setFirstName("A"+counter);
		customer1.setPassword("p"+counter);
		
		Customer customer2 = new Customer();
		customer2.setLoginId(customerId++);
		customer2.setFirstName("A"+counter);
		customer2.setPassword("p"+counter);
		
		
		customerDAO.addCustomer(customer1);
		customerDAO.addCustomer(customer2);
		
		Card card1 = new Card(counter, "Card Name "+counter, customer1);
		Card card2 = new Card(counter+1, "Card Name "+counter, customer1);
		Card card3 = new Card(counter+2, "Card Name "+counter, customer2);

		
		card1.setNumber(baseInfoId++);;
		card2.setNumber(baseInfoId++);;
		card3.setNumber(baseInfoId++);;
		
		
		cardDAO.addCard(card1);
		cardDAO.addCard(card2);
		cardDAO.addCard(card3);
		
		ArrayList<Customer> listCustomers = (ArrayList<Customer>) customerDAO.getCustomers();
		ArrayList<Card> listCards = (ArrayList<Card>) cardDAO.getCards();
		
		
		return "forward:/home.html";
	}
}
